
import React from 'react'
import {connect} from 'react-redux';
import {login,getUserData} from '../redux/auth.redux';
import {Redirect} from 'react-router-dom';
// import axios from 'axios';

// 两个reducer，每个reducer都有一个state
//合并reducer
@connect(
    state =>state.auth,
    {login,getUserData}
)
class Auth extends React.Component{
    constructor(props){
        super(props)
        this.state= {
            user:''
        }
    }
    render() {
        console.log(this.props)
        console.log(this.props.isAuth);
        console.log(this.state)
        console.log(this.state.user)
        const RedirectToHome = <Redirect to='/' />
        return(
            <div>
                <h5>登陆注册页面</h5>
                <h6 style={{color:'#f00'}}>
                    {this.props.isAuth ? null : `${this.props.user}:您需要登陆`}
                </h6>
                <input type='text' placeholder='userName' />
                <input type='password' placeholder='password' />
                <button onClick={this.props.login} >登陆</button>
            </div>
        )
    }
    componentDidMount() {
    
        // console.log(axios)
        // axios.get('/data').then(res=>{
        //     console.log(res);
        //     this.setState({
        //         userName:res.data[0].user
        //     })
        // })
        this.props.getUserData();
        console.log(this.props.userName)
    }
    componentWillReceiveProps(newProps) {
        console.log('hhhhhhhhhhhh')
        console.log(newProps)
        this.setState({
            user:newProps.user
        })
    }
};

export default Auth;